<?php
include '../includes/cDatabase.php';
include '../includes/cPage.php';
include '../includes/cDates.php';

$cPage = new page("Injury Table");
echo $cPage->getTitle();
echo $cPage->pageStringStart();
echo $cPage->contentStringStart();

$cDatabase = new database();

$connect = $cDatabase->connectToDatabase();
$activeDatabase = $cDatabase->getActiveDatabase($connect);

$db = $cDatabase->selectDatabase($connect, $activeDatabase);

$result = $cDatabase->DoesTableExist($connect, 'injury');
if ($result == FALSE)
{
	// Create this table
	$cDatabase->createInjuryTable($connect);
}
else
{
	//echo "<BR>Table exists";
}

$selectArray[0] = '*';
$result = $cDatabase->selectFromDatabase($connect, 'injury', $selectArray, NULL, NULL, NULL, NULL);
	
if($result != 0)
{
	echo "<table border='1'><thead><tr>";
	$finfo = mysqli_fetch_fields($result);
	for($i = 0; $i < mysqli_num_fields($result); $i++)
	{
		if($finfo[$i]->name == 'player' || $finfo[$i]->name == 'team' || $finfo[$i]->name == 'injury' || $finfo[$i]->name == 'returnDate')
		{
			echo "<th>" .$finfo[$i]->name."</th>";
		}
	}
	echo "  </tr></thead><tbody>";

	for ($i = 0; $i < mysqli_num_rows($result); $i++)
	{
		$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
		
		echo "<td>".$row['player']."</td>";
		echo "<td>".$row['team']."</td>";
		echo "<td>".$row['injury']."</td>";
		echo "<td>".$row['returnDate']."</td></tr>";
	}
	echo "</tbody>
	</table>";
}  //end else

echo $cPage->getContentStringEnd();
echo $cPage->getMenu();
echo $cPage->getClear();
echo $cPage->pageStringEnd();
echo $cPage->getFooter();
?>